package com.example.parkingproject.controller;

import com.example.parkingproject.jopo.entity.Allega;
import com.example.parkingproject.result.JsonResult;
import com.example.parkingproject.service.AllegaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/allega")
@Slf4j
public class allegaController {
    @Autowired
    AllegaService allegaService;

    @RequestMapping("/newAllega")
    public JsonResult newAllege(@RequestBody Allega allega) {
        log.debug("传入参数{}", allega);
        allegaService.newAllega(allega);
        return JsonResult.ok();
    }

    @RequestMapping("/loadAllega")
    public JsonResult<List<Allega>> loadAllega(String cardId) {
        log.debug("传入查询申述参数{}",cardId);
        List<Allega> list = allegaService.loadAllega(cardId);
        log.debug("查询出的结果为{}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("/delete")
    public JsonResult delete(Integer id) {
        log.debug("传入参数{}", id);
        allegaService.delete(id);
        return JsonResult.ok();
    }

    @RequestMapping("/handleLoadAllega")
    public JsonResult<List<Allega>> handleLoadAllega(String cardId) {
        log.debug("传入查询参数为{}",cardId);
        List<Allega> list = allegaService.handleLoadAllega(cardId);
        log.debug("查询出的结果为{}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("/getAllage")
    public JsonResult<Allega> getAllage(Integer id) {
        Allega allega = allegaService.getAllage(id);
        return JsonResult.ok(allega);
    }

    @RequestMapping("/adminLoadAllega")
    public JsonResult<List<Allega>> adminLoadAllega() {
        List<Allega> list = allegaService.adminLoadAllega();
        log.debug("查出参数为{}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("/handle")
    public JsonResult handle(@RequestBody Allega allega) {
        allegaService.handle(allega);
        return JsonResult.ok();
    }

    @RequestMapping("/userGetAllage")
    public JsonResult<Allega> userGetAllage(Integer id) {
        log.debug("传入参数id{}",id);
        Allega allega = allegaService.userGetAllage(id);
        return JsonResult.ok(allega);
    }

    @RequestMapping("/getHistory")
    public JsonResult<Integer> getHistory() {
        Integer count = allegaService.getHistory();
        log.debug("传出参数{}", count);
        return JsonResult.ok(count);
    }

    @RequestMapping("/update")
    public JsonResult update(@RequestBody Allega allega) {
        log.debug("传入参数{}", allega);
        allegaService.update(allega);
        return JsonResult.ok();
    }


    @RequestMapping("/groupAllega")
    public JsonResult<List<Integer>> groupAllega() {
        List<Integer> list = allegaService.groupAllega();
        return JsonResult.ok(list);
    }

    @RequestMapping("/adminHandleLoadAllega")
    public JsonResult<List<Allega>> adminHandleLoadAllega(){
        List<Allega> list  = allegaService.adminHandleLoadAllega();
        return JsonResult.ok(list);
    }
}
